using System;
using System.Collections.Generic;
using SpellCore;

namespace SpellerExampleClient.Tests
{
    internal class MockProvider : ISpellCheckEngine
    {
        private static IList<string> _goodWords;

        private CheckingResult _expectedStatus = CheckingResult.Unknown;
        private IEnumerable<SimilarityCheckResult> _expectedSuggestions;

        public MockProvider()
        {
            _goodWords = new List<string>();
            _goodWords.Add("good");
            _goodWords.Add("better");
            _goodWords.Add("best");

            List<SimilarityCheckResult> __expectedSuggestions = new List<SimilarityCheckResult>();
            __expectedSuggestions.Add(new SimilarityCheckResult(SimilarityCheckResult.UnknownScore, "good"));
            __expectedSuggestions.Add(new SimilarityCheckResult(SimilarityCheckResult.UnknownScore, "better"));
            __expectedSuggestions.Add(new SimilarityCheckResult(SimilarityCheckResult.UnknownScore, "best"));
            _expectedSuggestions = __expectedSuggestions;
        }

        public CheckingResult ExpectedStatus
        {
            get { return _expectedStatus; }
            set { _expectedStatus = value; }
        }

        public IEnumerable<SimilarityCheckResult> ExpectedSuggestions
        {
            get { return _expectedSuggestions; }
            set { _expectedSuggestions = value; }
        }

        public CheckingResult GetWordStatus(string word)
        {
            if (_goodWords.Contains(word))
            {
                return CheckingResult.Good;
            }
            return _expectedStatus;
        }

        public bool CanSupportAdditions()
        {
            return false;
        }

        public void AddWordAsGood(string word)
        {
            throw new NotSupportedException("cannot do an add good word operation on a HunSpellWrapper class");
        }

        public bool CanSupportBadWords()
        {
            return false;
        }

        #region ISpellCheckEngine Members

        /// <summary>
        /// Adds a word to the known bad word store
        /// </summary>
        /// <param name="word"></param>
        /// <exception cref="NotSupportedException">When CanSupportBadWords is false</exception>
        public void AddWordAsBad(string word)
        {
            throw new NotImplementedException();
        }

        #endregion

        public bool CanProvideSuggestions()
        {
            return true;
        }

        #region ISuggestionProvider Members

        public IEnumerable<SimilarityCheckResult> GetSuggestions(string word)
        {
            return ExpectedSuggestions;
        }

        #endregion

        ~MockProvider()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
        }

        private bool _isDisposed;

        private void Dispose(bool disposing)
        {
            if (_isDisposed)
            {
                return;
            }
            _isDisposed = true;
            if (disposing)
            {
                //release managed resources
            }
            //release unmanaged resources
        }
    }
}